<script setup lang="ts">
import {useAuthStore} from "@/stores";
import axios from "axios";

const authStore = useAuthStore();
const hitokotoData = reactive<{ content: string, from: string }>({content: '', from: ''})
const renderWelcome = () => {
  const currentDate = new Date();
  const hour = currentDate.getHours();
  // 补上对应精神状态的emoji
  if (hour >= 0 && hour < 6) {
    return '凌晨好! 😴';
  } else if (hour >= 6 && hour < 12) {
    return '早上好! ☕';
  } else if (hour >= 12 && hour < 18) {
    return '中午好! 🤡';
  } else if (hour >= 18 && hour < 24) {
    return '晚上好! 😫';
  } else {
    return '夜深了! 💤';
  }
}
axios.get('https://v1.hitokoto.cn/ ').then(({data}) => {
  hitokotoData.content = data.hitokoto
  hitokotoData.from = data.from_who ? `${data.from_who}-${data.from}` : `${data.from}`
})
</script>
<template>
  <n-card class="welcome" h-fit>
    <template #header>{{ `${renderWelcome()}  ${authStore.loginUser?.nickname}` }}</template>
    <n-blockquote>{{ `${hitokotoData.content} --${hitokotoData.from}` }}</n-blockquote>
  </n-card>
</template>
<style scoped>
</style>
